<template>
  <el-dialog v-model="props.visible" :footer="false" @close="emits('close')">
    <template #header="{ titleId, titleClass }">
      <div class="my-header flex">
        <h4 :id="titleId" :class="titleClass">
          <el-icon>
            <WorkFlowIcon />
          </el-icon>
          流程配置
        </h4>
        <div class="search-box" v-if="isShowSearch">
          <el-input
            v-model="searchKeyword"
            placeholder="搜索流程"
            class="search-input"
          />
          <el-button
            link
            @click="handleSearch"
            class="search-button"
            :icon="Search"
          >
          </el-button>
        </div>
      </div>
    </template>
    <div>
      <el-carousel
        :autoplay="false"
        arrow="never"
        trigger="click"
        indicator-position="outside"
        height="50vh"
        ref="carousel"
        @change="handleCarouselChange"
      >
        <el-carousel-item label="1" name="first">
          <div class="firstPage">
            <div>
              <el-table
                ref="multipleTableRef"
                :data="tableData"
                style="width: 100%"
                height="43vh"
                table-layout="auto"
                @selection-change="handleSelectionChange"
              >
                <el-table-column type="selection" />
                <el-table-column property="phone" label="流程名称" />
                <el-table-column property="phone" label="预览" align="center" />
                <el-table-column property="phone" label="备注" align="center" />
                <el-table-column
                  property="phone"
                  label="创建人"
                  align="center"
                />
                <el-table-column
                  property="phone"
                  label="创建时间"
                  align="center"
                />
              </el-table>
              <div class="flex paginationBox">
                <el-pagination
                  background
                  layout="prev, pager, next"
                  :total="50"
                />
                <el-button type="default" @click="emits('close')"
                  >确定</el-button
                >
              </div>
            </div>
          </div>
        </el-carousel-item>
        <el-carousel-item label="2" name="second">
          <div class="secondPage flex-column">
            <div class="flex">
              <div class="workflow">
                <el-timeline style="max-width: 600px">
                  <el-timeline-item
                    center
                    hide-timestamp
                    v-for="(item, index) in workflowData"
                    :key="item.id"
                  >
                    <template #dot> {{ item.name }} </template>
                    <div style="margin-left: 0.5rem; padding: 10px">
                      <p>选择成员</p>
                      <el-select
                        v-model="member[index]"
                        placeholder="请选择成员"
                        style="width: 240px"
                      >
                        <el-option
                          v-for="m in item.member"
                          :key="m.id"
                          :label="m.name"
                          :value="m.id"
                          :disabled="m.disabled"
                        />
                      </el-select>
                    </div>
                  </el-timeline-item>
                </el-timeline>
              </div>
              <div class="rules">
                <div>
                  <h4>流程规则</h4>
                  <p>审批节点：允许同时存在多个审批人</p>
                  <p>多人审批时：需所有审批人同意</p>
                  <p>审批人为空时：自动通过</p>
                </div>
              </div>
            </div>
            <div class="button">
              <el-button type="default" @click="nextPage"> 确定 </el-button>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </el-dialog>
</template>
<script setup>
import { Search } from "@element-plus/icons-vue";
import WorkFlowIcon from "@/assets/customIcon/WorkFlow.vue";
const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  row: {
    type: Object,
    default: () => {},
  },
});
const emits = defineEmits(["close"]);
const dialogVisible = ref(true);
// const Edit = () => h(WorkFlowIcon);
const carousel = ref(null);
const isShowSearch = ref(false);
const searchKeyword = ref("");
const selectedWorkFlow = ref("");
const handleSearch = () => {
  console.log("handleSearch");
};
const tableData = ref([]);
const handleSelectionChange = (val) => {};
const member = ref([]);
const workflowData = ref([
  {
    id: 1,
    name: "编辑",
    member: [
      { id: 1, name: "张三" },
      { id: 2, name: "李四" },
    ],
  },
  {
    id: 2,
    name: "校对",
    member: [
      { id: 1, name: "张三" },
      { id: 2, name: "李四" },
    ],
  },
  {
    id: 3,
    name: "审核",
    member: [
      { id: 1, name: "张三" },
      { id: 2, name: "李四" },
    ],
  },
  {
    id: 24,
    name: "审定",
    member: [
      { id: 1, name: "张三" },
      { id: 2, name: "李四" },
    ],
  },
]);
const handleCarouselChange = (currentIndex, preIndex) => {
  console.log(currentIndex, preIndex);
  if (currentIndex == 0) {
    // 翻到第一页
    isShowSearch.value = true;
  } else {
    if (!selectedWorkFlow.value) {
      // 翻回去
      console.log(carousel.value);
      ElMessage({
        message: "请先选中工作流",
        type: "warning",
        grouping: true,
      });
      carousel.value.setActiveItem('first');
      // carousel.value.prev();
    } else {
      // 翻到第二页
      isShowSearch.value = false;
    }
  }
};
const nextPage = () => {
  // carousel.value.next();
  // console.log(carousel.value.activeIndex);
};
watch(carousel, (val) => {
  console.log(val);
  console.log(val.activeIndex);
  // console.log(val.value.activeIndex);
  if (val.activeIndex === 0) {
    isShowSearch.value = true;
  } else {
    isShowSearch.value = false;
  }
});

onMounted(() => {
  // dialogVisible.value = props.visible;
  // 获取需要的数据
  console.log(props.row, "props.row");
  // console.log(document.querySelector(".el-carousel__item.is-active"));
  console.log(carousel.value?.activeIndex);
});
</script>
<style lang="scss" scoped>
.el-dialog__title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.my-header {
  height: 34px;
  justify-content: space-between;
  .search-box {
    display: flex;
    align-items: center;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    margin-right: 15px;
    .search-input {
      flex: 1;
      border-right: 1px solid #dcdfe6;
      :deep(.el-input__wrapper) {
        box-shadow: none;
      }
      .el-input__icon {
        cursor: pointer;
        font-size: 18px;
        &:hover {
          color: #409eff; /* Element Plus 主色调 */
        }
      }
    }
    .search-button {
      height: 100%;
      padding: 0 8px;
    }
  }
}
:deep(.el-carousel__container) {
  border-bottom: 1px solid #ccc;
}
:deep(.el-carousel__button) {
  width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0;
}
.firstPage,
.secondPage {
  width: 100%;
  height: 100%;
}
.firstPage {
  .paginationBox {
    padding: 10px;
    justify-content: flex-end;
    gap: 20px;
  }
}
.secondPage {
  border-top: 1px solid #ccc;
  & > .flex {
    height: 90%;
    .workflow,
    .rules {
      width: 50%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .workflow {
      :deep(.el-timeline-item__dot) {
        background-color: #fff;
      }
    }
    .rules {
      h4 {
        color: #000;
        font-weight: bold;
        font-size: 22px;
        line-height: 40px;
      }
      p {
        font-size: 15px;
        font-family: "SimSun";
        line-height: 26px;
        text-indent: 1em;
      }
    }
  }
  .button {
    text-align: end;
    padding: 5px 20px;
  }
}
</style>
